#!/usr/bin/env python
#encoding : utf-8

from jinja2_template import render
from response import Response
import os
import sys

class BaseHandler(object):
	def __init__(self, req):
		self._req = req
		self._file_type = False
		self._input = {}
		self._output = {}

	def Process(self):
		return True

	def set_engine(self, engine):
		self._output['engine'] = engine

	def set_template(self, template):
		self._output['template'] = template


	def _response(self):
		if 'template' not in self._output:
			return Response('no template error')
		r = {}
		r['template'] = self._output['template']
		r['data'] = self._output['data']
		if 'engine' in self._output:
			r['engine'] = self._output['engine']

		return Response(render(**r))

	def run(self):

		if not self.process():
			return self._response()

		if self._file_type:
			file_path = os.path.join("/root/staff-manage/src/static/css/staff_manage.css")
			print file_path
			file_content = open(file_path, 'r').read()
			resp = Response(file_content)
			resp.set_header('Content-Type', 'text/css')
			return resp
		return self._response()

if __name__ == '__main__':
	pass
